function firstPage(){
    var form = document.getElementById('form');
    document.getElementById("pageNum").value = "1";
    form.submit();
}
function lastPage(){
    var form = document.getElementById('form');
    document.getElementById("pageNum").value = document.getElementById("totalPages").value;
    form.submit();
}
function nextPage(){
    var form = document.getElementById('form');
    var totalPages=document.getElementById("totalPages");
    var pageNum=document.getElementById("pageNum");
    pageNum.value=parseInt(pageNum.value)+1;
    document.getElementById("pageNum").value=pageNum.value;
    if(pageNum.value>=totalPages.value)
        pageNum.value=totalPages.value;
    document.getElementById("pageNum").value=pageNum.value;
    form.submit();
}
function prePage(){
    var form = document.getElementById('form');
    var pageNum=document.getElementById("pageNum");
    pageNum.value=pageNum.value-1;
    if(pageNum.value<=0)
        pageNum.value=1;

    document.getElementById("pageNum").value=pageNum.value;
    form.submit();
}
function searchPage(){
    var form = document.getElementById('form');
    var pageNum=document.getElementById("searchPageNum");
    var totalPages=document.getElementById("totalPages").value;
    if (pageNum.value>totalPages)
        pageNum.value=totalPages;
    if(pageNum.value<=0)
        pageNum.value=1;
    document.getElementById("pageNum").value=pageNum.value;
    form.submit();
}


function sortTemperature(){
    var sort = document.getElementById('sort');
    var form = document.getElementById('form');

    if ( sort.value != "temperature" && sort.value != "temperature desc")
        document.getElementById('sort').value="temperature";
    else if(sort.value == "temperature")
        document.getElementById('sort').value = "temperature desc";
    else if(sort.value == "temperature desc")
        document.getElementById('sort').value = "temperature";

    form.submit();
}

function sortDate(){
    var sort = document.getElementById('sort');
    var form = document.getElementById('form');

    if ( sort.value != "date" && sort.value != "date desc")
        document.getElementById('sort').value="date";
    else if(sort.value == "date")
        document.getElementById('sort').value = "date desc";
    else if(sort.value == "date desc")
        document.getElementById('sort').value = "date";

    form.submit();
}

function selectBody(){
    var body = document.getElementById('body');
    var form = document.getElementById('form');

    if ( body.value != "=" && body.value != "!=")
        document.getElementById('body').value="=";
    else if(body.value == "=")
        document.getElementById('body').value = "!=";
    else if(body.value == "!=")
        document.getElementById('body').value = "";

    form.submit();
}

function selectIstreatment(){
    var istreatment = document.getElementById('istreatment');
    var form = document.getElementById('form');
    console.log(document.getElementById('istreatment').value);
    if ( istreatment.value != "true" && istreatment.value != "false")//{document.getElementById('istreatment').value="true";console.log(1);}
        document.getElementById('istreatment').value="true";
    else if(istreatment.value == "true")//{document.getElementById('istreatment').value = "false";console.log(2);}
        document.getElementById('istreatment').value = "false";
    else if(istreatment.value == "false")//{document.getElementById('istreatment').value = "";console.log(3);}
        document.getElementById('istreatment').value = "";
    console.log(document.getElementById('istreatment').value);
    form.submit();
}

function selectIsolated(){
    var isolated = document.getElementById('isolated');
    var form = document.getElementById('form');
    console.log(document.getElementById('isolated').value);
    if ( isolated.value != "true" && isolated.value != "false")
        document.getElementById('isolated').value="true";
    else if(isolated.value == "true")
        document.getElementById('isolated').value = "false";
    else if(isolated.value == "false")
        document.getElementById('isolated').value = "";
    console.log(document.getElementById('isolated').value);
    form.submit();
}

function selectInschool(){
    var inschool = document.getElementById('inschool');
    var form = document.getElementById('form');
    console.log(document.getElementById('inschool').value);
    if ( inschool.value != "true" && inschool.value != "false")
        document.getElementById('inschool').value="true";
    else if(inschool.value == "true")
        document.getElementById('inschool').value = "false";
    else if(inschool.value == "false")
        document.getElementById('inschool').value = "";
    console.log(document.getElementById('inschool').value);
    form.submit();
}

function selectInguan(){
    var inguan = document.getElementById('inguan');
    var form = document.getElementById('form');
    console.log(document.getElementById('inguan').value);
    if ( inguan.value != "true" && inguan.value != "false")
        document.getElementById('inguan').value="true";
    else if(inguan.value == "true")
        document.getElementById('inguan').value = "false";
    else if(inguan.value == "false")
        document.getElementById('inguan').value = "";
    console.log(document.getElementById('inguan').value);
    form.submit();
}

function searchKeyword() {
    //var searchkeyword = $('input[name=searchkeyword]').val();
    var searchkeyword=document.getElementById("searchKeyword").value
    console.log(searchkeyword);
    if (keyword !== "" && keyword != "-1") {
        var form = document.getElementById('form');
        document.getElementById("keyword").value = searchkeyword;
        document.getElementById("sort").value = "-1";
        document.getElementById("pageNum").value = "1";
        form.submit();
    }
}